import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store = new Vuex.Store({
	state: {
		login: false,
		userInfo: {},
		sysUser: {},
		sysMenus:{},
		userObj:{},
		cutomerObj:{},
		stockDetailObj:{},
		stockObj:{},
		outboundObj:{},
	},
	/**
	 * 突变
	 */
	mutations: {
		login(state, provider) {
			console.log(state, provider)
			state.login = true;
			state.userInfo = provider.userInfo;
			uni.setStorageSync("userInfo", provider.userInfo);
			if (provider.token) {
				uni.setStorageSync("token", provider.token);
			}
			if (provider.sysUser) {
				state.sysUser = provider.sysUser;
				uni.setStorageSync("sysUser", provider.sysUser);
			}
			if (provider.sysMenus) {
				state.sysMenus = provider.sysMenus;
				uni.setStorageSync("sysMenus", provider.sysMenus);
			}
		},
		logout(state) {
			state.userInfo = {};
			state.sysUser = {};
			state.sysMenus = {};
			state.login = false;
			uni.clearStorageSync("userInfo");
			uni.clearStorageSync("token");
			uni.clearStorageSync("sysUser");
			uni.clearStorageSync("sysMenus");
		},
		setEditUserObj(state,userObj){
			console.log(state, userObj)
			state.userObj=userObj;
		},
		setCutomerObj(state,cutomerObj){
			console.log(state, cutomerObj)
			state.cutomerObj=cutomerObj;
		},
		setStockDetailObj(state,stockDetailObj){
			state.stockDetailObj=stockDetailObj;
		},
		setStockObj(state,stockObj){
			state.stockObj=stockObj;
		},
		setOutboundObj(state,outboundObj){
				state.outboundObj=outboundObj;
		}
		
	}, 
	/**
	 * 获取
	 */
	getters: {
		// userInfo(state, getters) {
		// 	console.log(state)
		// 	return 	uni.getStorageSync("userInfo")
		// }
	}
})
export default store;
